
<script type="text/javascript">
	var nodeAjaxUrl="<{u('SysNode/getNodeListByPid')}>";
	//获得父级分类ID
	var path = '<{$obj.path}>';
	var pid_array = path.split("/");

	var pid = '<{$obj.category_id}>';
	var pid2 = pid_array[0];


$(function(){
	//如果当前分类是三级分类，则替换一级分类ID和二级分类ID，以供自动选择判断使用
	if(pid_array.length==4 || pid_array.length==3){
		pid = pid_array[0];
		pid2 = pid_array[1]; 
	}
	//分类名称获得焦点
	$("#title").focus();

	function getSelectedText(obj){
		return $('#'+obj).find("option:selected").text()
	}
	//初始化一级分类列表的Ajax方法
	function initLevelOneCategory(){
		$.get(nodeAjaxUrl,{pid:"0"},function(data){
			var obj = data;//$.parseJSON(data);
				var optionStr = "";
				for(i=0;i<obj.length;i++){
					optionStr += "<option value='" + obj[i].id + "'>" + obj[i].title + "[" + obj[i].name +"]</option>";
				}
				$("#pid").html(optionStr);
				//遍历pid的option来进行自动选择
				$('#pid option').each(function(){
					if($(this).val()==pid){
						$(this).attr("selected","selected");
						//触发一级分类列表change事件，用来显示二级列表
						$("#pid").change();
					}
				});
		})	
	}
	
	//动态绑定一级分类change事件，异步获取子分类赋值给pid2
	$("#pid").bind("change",function(){
		if($(this).val()!=0){
			$.get(nodeAjaxUrl,{pid:""+$(this).val()+""},function(data){
			var obj = data;//$.parseJSON(data);

				var optionStr = "";
				for(i=0;i<obj.length;i++){
					optionStr += "<option value='" + obj[i].id + "'>" + obj[i].title + "[" + obj[i].name +"]</option>";
				}
				$("#pid2").html(optionStr);
				
				//遍历pid2的option来进行自动选择
				$('#pid2 option').each(function(){
      				if($(this).val()==pid2){
						$(this).attr("selected","selected");
						//触发二级分类列表change事件，用来显示三级列表
						$("#pid2").change();
					}
  				});
			
			})	
		}else{
			$("#pid2").html('');
			$("#pid3").html('');
		}
		
	})
	//动态绑定二级分类change事件，异步获取子分类赋值给pid3
	$("#pid2").bind("change",function(){
		$.get(nodeAjaxUrl,{pid:""+$(this).val()+""},function(data){
			
			var obj = data;//$.parseJSON(data);

				var optionStr = "";
				for(var i=0;i<obj.length;i++){
					optionStr += "<option value='" + obj[i].id + "'>" + obj[i].title + "[" + obj[i].name +"]</option>";
				}
				$("#pid3").html(optionStr);

			
		})
	})	
	var isMenu = "<{$obj.is_menu}>";
	if(isMenu == 1){$("#show").show();}
	$("#isMenu").bind('click',function () {$("#show").show();$("input[name='group']").attr('checked',false);});
	$("#noMenu").bind('click',function () {$("#show").hide();$("input[name='group']").attr('checked',false);});

	//一些页面加载就执行的操作
	initLevelOneCategory();


	$('#nodeForm').submit(function () {
		if($('#pid').val()==null){
			layer.msg("请指定顶级菜单");
			return false;
		}
		var level=1;
		var tip='';
		if($('#pid2').val()==null){
			level=2;
			tip='['+getSelectedText('pid')+']';
		}else{
			level=3;
			tip='['+getSelectedText('pid')+']'+' - '+'['+getSelectedText('pid2')+']';
		}

		if(!window.confirm("将作为"+level+"级权限\n"+"位于"+tip+' 之下')){
			return false;
		}

		<{if $opt eq 1}>
			var postUrl="<{u('Dev/SysNode/insert')}>";
        <{else}>
			var postUrl="<{u('Dev/SysNode/update')}>";
		<{/if}>
		$.post(postUrl,$('form').serialize(),function(result){
			if(result.status==0){
				layer.msg("权限修改成功");
				LoadAjaxContent(result.url);
				//location.href=result.url;
			}else{
				layer.msg(result.info);
			}
		},'json');





		return false;
	})
})
</script>
<div class="box">
	<div class="box-content">
<fieldset>
	<legend>权限项管理</legend>
<form id="nodeForm" style="margin: 1em" class="form-horizontal">
	<input type="hidden" name="id" value="<{$obj.id|default:0}>" />
	<div class="form-group">
		<label class="col-sm-1 control-label">标题</label>
		<div class="col-sm-2"><input type="text" class="form-control" value="<{$obj.title}>"  name="title" required/></div>
	</div>
	<div class="form-group">
		<label class="col-sm-1 control-label">名称</label>
		<div class="col-sm-2"><input type="text" class="form-control" value="<{$obj.name}>"  name="name" required/></div>
	</div>

	<div class="form-group">
		<label class="col-sm-1 control-label">父级</label>
		<div class="col-sm-9">
		<select id="pid" name="pid" size="15" style="float:left;"></select>
		<select id="pid2" name="pid2" size="15" style="float:left;"></select>
		<select id="pid3" name="pid3" size="15" style="float:left;" disabled="disabled"></select>
		</div>
	</div>


	<div class="form-group">
		<label class="col-sm-1 control-label">状态</label>
		<div class="radio-inline">
			<label>
				<input type="radio" value="1" name="status" <{if $obj.status == 1}> checked <{/if}> > 启用
				<i class="fa fa-circle-o"></i>
			</label>
		</div>
		<div class="radio-inline">
			<label>
				<input type="radio" value="0" name="status" <{if $obj.status == 0}> checked <{/if}>> 禁用
				<i class="fa fa-circle-o"></i>
			</label>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-1 control-label">是否菜单</label>
		<div class="radio-inline">
			<label>
				<input type="radio" value="1" name="is_menu" <{if $obj.is_menu == 1}> checked <{/if}>> 菜单
				<i class="fa fa-circle-o"></i>
			</label>
		</div>
		<div class="radio-inline">
			<label>
				<input type="radio" value="0" name="is_menu" <{if $obj.is_menu == 0}> checked <{/if}>> 非菜单
				<i class="fa fa-circle-o"></i>
			</label>
		</div>
	</div>
	<div class="form-group">
		<label class="col-sm-1 control-label">排序,降序显示</label>
		<div class="col-sm-2"><input type="text" class="form-control" value="<{$obj.sort}>"   name="sort" required/></div>
	</div>
	<div class="form-group">
		<div class="col-sm-1 "></div>
		<div class="col-sm-2"><input type="submit" id="submit" class="btn btn-primary" value="提交"></div>
	</div>
</form>

</fieldset>
	</div>
</div>